<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Conf
 *
 * @author Ramiro
 */
//$conf = new Conf();
//echo $conf->getTokenIdusuario("AAAAAAAAAAAA");

class Conf {

    private $HOST;
    private $USER;
    private $PASSWORD;
    private $DATABASE;
    static private $instancia = NULL;
    private $SERIAL_ID = "1321389432419848749";

    public function getSERIAL_ID() {
        return $this->SERIAL_ID;
    }

    public function getHour() {
        return date('dmYhi');
    }

    public function getTokenIdusuario($id) {
        // echo "\n".$this->getHour().">>>>>>>>>>       ";
        $result = $this->SERIAL_ID . md5($id . "B@ncoCh3ve") . $this->getHour();

        //  $result = $this->SERIAL_ID . "asdasdasdasdasdasdasdas6d54a6sd6as54d" . $this->getHour();

        $tmp = "" . hash('md5', $result);
        //   echo "\n".$tmp.">>>>>>>>>>       ";

        $val = $this->bchexdec($tmp);
        //   echo $id."<br/>";

        $resultado = bcmod($val, 999999);
        //   echo $resultado."<br/>";
        if ($resultado < 999999) {
            $resultado = $resultado - 999999;
        }
        $valor = abs($resultado);
        return $valor;
    }

    function bchexdec($hex) {
        static $hexdec = array(
    "0" => 0,
    "1" => 1,
    "2" => 2,
    "3" => 3,
    "4" => 4,
    "5" => 5,
    "6" => 6,
    "7" => 7,
    "8" => 8,
    "9" => 9,
    "a" => 10,
    "b" => 11,
    "c" => 12,
    "d" => 13,
    "e" => 14,
    "f" => 15
        );

        $dec = 0;

        for ($i = strlen($hex) - 1, $e = 1; $i >= 0; $i--, $e = bcmul($e, 16)) {
            $factor = $hexdec[$hex[$i]];
            $dec = bcadd($dec, bcmul($factor, $e));
        }

        return $dec;
    }

    function RawToMD5($raw) {
        $result = '';
        foreach (str_split($raw) as $i => $byte) {
            $result .= str_pad(dechex(ord($byte)), 2, '0', STR_PAD_LEFT);
        }
        return $result;
    }

    private function __clone() {
        trigger_error('Clone is not allowed.', E_USER_ERROR);
    }

    public function __construct() {
        $this->HOST = 'localhost';
        $this->USER = 'root';
        $this->PASSWORD = '';
        $this->DATABASE = 'banco';
    }

    public function getHOST() {
        return $this->HOST;
    }

    public function getUSER() {
        return $this->USER;
    }

    public function getPASSWORD() {
        return $this->PASSWORD;
    }

    public function getDATABASE() {
        return $this->DATABASE;
    }

    static public function getInstancia() {
        if (self::$instancia == NULL) {
            self::$instancia = new Conf();
        }
        return self::$instancia;
    }

}

?>
